<template>
	<view>
		<form @submit="formSubmit" >
			标题<input class="uni-input" name="title" :value="info.title" />
			<view class="uni-textarea">
		        内容<textarea name="content" :value="info.content" />
			</view>
			<button form-type="submit">发布</button>
		</form>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id:false,
				info:{},
			}
		},
		methods: {
			formSubmit: function(e){
				var formdata = e.detail.value;
				if(this.id){
					formdata._method='PUT';
					this.api.request({url:'/api/v1/article/'+this.id,method:'POST',formdata:formdata,
					}).then(res=>{
						console.log(res);
						uni.redirectTo({
						    url: '../../forum/articleinfo?id='+res.data.id
						});
					});
				}else{
					this.api.request({url:'/api/v1/article',method:'POST',formdata:formdata,
					}).then(res=>{
						uni.redirectTo({
						    url: '../../forum/articleinfo?id='+res.data.id
						});
					});
				}
				
			},
		},
		onLoad(params){
			this.id = params.id;
			if(this.id){
				this.api.request({url:'/api/v1/article/'+this.id,method:'GET',
				}).then(res=>{
					this.info = res.data;
					console.log(res);
				});
			}
			
		}
	}
</script>

<style>

</style>
